home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / hotkey / AutoHotkey104504_Install.exe / Extras / Run this to install syntax highlighting for ConTEXT.ahk < prev    next >
Text File  |  2006-11-05  |  10KB  |  350 lines

  1. ; Installs AutoHotkey syntax highlighting for the ConTEXT editor.
  2. ;
  3. ; Created by foom
  4. ; Color theme is based on the UnrealScript highlighter found on:
  5. ; http://wiki.beyondunreal.com/wiki/ConTEXT/UnrealScript
  6. ; Which itself resembles the highlighting syntax/theme of the UScript Editor in UnrealEd⌐ by Epic Games Inc.
  7. ;
  8. ; Report Problems at:
  9. ; http://www.autohotkey.com/forum/topic10895.html
  10. ;
  11. ; 10.29.2006
  12. ; - Initial release.
  13. ; 11.09.2006
  14. ; - Fixed "if" not beeing highlighted. Maybe other words too.
  15. ; - Fixed don't display the succesfully installed msgbox if user cancels contextdir selection.
  16. ; 05.11.2006
  17. ; - Fixed a typo which prevented the codetemplate from being installed if it allready existed.
  18.  
  19. SetBatchLines -1
  20. #SingleInstance force
  21.  
  22.  
  23. ; Discover where AutoHotkey and its related files reside:
  24. RegRead, AhkDir, HKLM, SOFTWARE\AutoHotkey, InstallDir
  25. if (ErrorLevel or not FileExist(AhkDir . "\AutoHotkey.exe"))  ; Not found, so try best-guess instead.
  26.     SplitPath, A_AhkPath,, AhkDir
  27.  
  28. ; Get path to ConTEXT:
  29. RegRead, contextDir, HKEY_LOCAL_MACHINE, SOFTWARE\Classes\Applications\ConTEXT.exe\shell\edit\command
  30. if contextDir
  31.     SplitPath, contextDir,, contextDir  ; This removes the following string from the end: \ConTEXT.exe "%1"
  32. else  ; Try a best-guess location.
  33.     contextDir = %A_ProgramFiles%\ConTEXT
  34. IfNotExist, %contextDir%
  35.     Gosub, selectcontextdir
  36.  
  37. ;Do not edit the settings below. You might, but don't! Edit the values in ConTEXT settings instead. You've been warned.
  38. highlightsettings=
  39. (
  40. Language:            AutoHotkey
  41. Filter:              AutoHotkey (*.ahk)|*.ahk
  42. HelpFile:            %AhkDir%\AutoHotkey.chm
  43. CaseSensitive:       0
  44. LineComment:         ;
  45.  
  46. //dont use blockcomments, context blockcomments are not ahk conform
  47. BlockCommentBeg:
  48. BlockCommentEnd:
  49.  
  50. IdentifierBegChars:  a..z A..Z _#
  51. IdentifierChars:     a..z A..Z _# 0..9
  52. NumConstBegChars:    0..9
  53. NumConstChars:       0..9 .abcdefhABCDEFH
  54.  
  55. EscapeChar:          `
  56. StringBegChar:       "
  57. StringEndChar:       "
  58. MultilineStrings:    0
  59. UsePreprocessor:     0
  60. CurrLineHighlighted: 1
  61.  
  62. SpaceCol:            clWhite $00400000
  63. Keyword1Col:         clAqua $00400000
  64. Keyword2Col:         clWhite $00320000 B
  65. Keyword3Col:         $00FFBC79 $00400000
  66. Keyword4Col:         clWhite $00620000
  67.  
  68. // clAqua $00400000
  69. Keyword5Col:         $00FFC0C0 $00400000
  70. IdentifierCol:       clWhite $00400000
  71. CommentCol:          $00909090 $00410000
  72. NumberCol:           clWhite $00400000
  73. StringCol:           clLime $00400000
  74. SymbolCol:           clWhite $00400000
  75.  
  76. // clGray $00400000
  77. PreprocessorCol:     $00FFC0C0 $00400000
  78. SelectionCol:        $00400000 $00BFFFFF
  79. CurrentLineCol:      clWhite $00600000
  80. MatchedBracesCol:    clYellow $00400000
  81.  
  82. OverrideTxtFgColor:  0
  83. BlockAutoindent:     1
  84. BlockBegStr:         {
  85. BlockEndStr:         }
  86.  
  87. )
  88.  
  89. commandstxt=%ahkdir%\extras\editors\syntax\commands.txt
  90. commandnamestxt=%ahkdir%\extras\editors\syntax\commandnames.txt
  91. functionstxt=%ahkdir%\extras\editors\syntax\functions.txt
  92. variablestxt=%ahkdir%\extras\editors\syntax\variables.txt
  93. keystxt=%ahkdir%\extras\editors\syntax\keys.txt
  94. keywordstxt=%ahkdir%\extras\editors\syntax\keywords.txt
  95.  
  96. AutoHotkeyctpl=%ahkdir%\extras\editors\syntax\AutoHotkey.ctpl
  97. AutoHotkeychl =%ahkdir%\extras\editors\syntax\AutoHotkey.chl
  98.  
  99.  
  100.  
  101. if (!FileExist(commandstxt) or !FileExist(functionstxt) or !FileExist(variablestxt) or !FileExist(keywordstxt) or !FileExist(keystxt) or !FileExist(commandnamestxt))
  102. {
  103.     MsgBox,16,Error, Couldn't find syntax files. Exiting.
  104.     exitapp
  105. }
  106.  
  107. Gosub, deletefiles
  108.  
  109. Loop, Read, %commandstxt%
  110. {
  111.     Command=
  112.     Desc=
  113.     Out=%A_LoopReadLine%
  114.     parse_template(Command, Desc, Out)
  115.     
  116.     loop
  117.     {
  118.         if command in %commandlist%
  119.             command:=command . "_"
  120.         else
  121.             break
  122.     }
  123.  
  124.     if commandlist
  125.         commandlist:=commandlist . "," . Command
  126.     else
  127.         commandlist:=command
  128.  
  129.     FullOut=[%Command% | %Desc%]`n%Out%`n`r`n
  130.     ahktemplate=%ahktemplate%%FullOut%
  131. }
  132.  
  133. commandlist=
  134.  
  135. Loop, Read, %functionstxt%
  136. {
  137.     Command=
  138.     Desc=
  139.     Out=%A_LoopReadLine%
  140.     parse_template(Command, Desc, Out)
  141.  
  142.     loop
  143.     {
  144.         if command in %commandlist%
  145.             command:=command . "_"
  146.         else
  147.             break
  148.     }
  149.  
  150.     if commandlist
  151.         commandlist:=commandlist . "," . Command
  152.     else
  153.         commandlist:=command
  154.  
  155.     FullOut=[%Command% | %Desc%]`n%Out%`n`r`n
  156.     ahktemplate=%ahktemplate%%FullOut%
  157. }
  158.  
  159. commandlist=
  160.  
  161. Loop, Read, %variablestxt%
  162. {
  163.     Command=
  164.     Desc=
  165.     Out=%A_LoopReadLine%
  166.     parse_template(Command, Desc, Out)
  167.  
  168.     FullOut=[%Command% | A_BuildInVariable]`n%Out%`n`r`n
  169.     ahktemplate=%ahktemplate%%FullOut%
  170. }
  171.  
  172. FileAppend, %ahktemplate%, %AutoHotkeyctpl%
  173.  
  174.  
  175.  
  176. ahkchl=
  177.  
  178. ;functions
  179. FileRead, syntaxfile, %functionstxt%
  180. ahkchl:="KeyWords1:" . parse_hl(syntaxfile, ",,," . a_space . "," . a_tab  . ",(,[,{,;,`n") . "`n`n"
  181.  
  182. ;commandnames (no preprozessor)
  183. FileRead, syntaxfile, %commandnamestxt%
  184. ahkchl:=ahkchl . parse_hl(syntaxfile, ",,," . a_space . "," . a_tab  . ",(,[,{,;,`n" ,"#",0) . "`n`n"
  185.  
  186. ;keys
  187. FileRead, syntaxfile, %keystxt%
  188. ahkchl:=ahkchl . "KeyWords2:" . parse_hl(syntaxfile, ",,," . a_space . "," . a_tab  . ",(,[,{,;,`n") . "`n`n"
  189.  
  190. ;keywords
  191. FileRead, syntaxfile, %keywordstxt%
  192. ahkchl:=ahkchl . "KeyWords3:" . parse_hl(syntaxfile, ",,," . a_space . "," . a_tab  . ",(,[,{,;,`n") . "`nforce`n`n`n"
  193.  
  194. ;built-in variables
  195. FileRead, syntaxfile, %variablestxt%
  196. ahkchl:=ahkchl . "KeyWords4:" . parse_hl(syntaxfile, ",,," . a_space . "," . a_tab  . ",(,[,{,;,`n") . "`n`n"
  197.  
  198. ;commandnames (only preprozessor)
  199. FileRead, syntaxfile, %commandnamestxt%
  200. ahkchl:=ahkchl . "KeyWords5:" . parse_hl(syntaxfile, ",,," . a_space . "," . a_tab  . ",(,[,{,;,`n" ,"#",1) . "`n`n"
  201.  
  202. ahkchl:=highlightsettings . "`n`n" . ahkchl 
  203.  
  204. FileAppend, %ahkchl%, %AutoHotkeychl%
  205.  
  206.  
  207. if FileExist(contextDir . "\Template\AutoHotkey.ctpl")
  208. {
  209.     MsgBox,36,Warning,%contextDir%\Template\AutoHotkey.ctpl already exists. Overwrite that file?
  210.     IfMsgBox, No
  211.         FileCopy, %AutoHotkeyctpl%, %contextDir%\Template\AutoHotkey.ctpl, 0
  212.     IfMsgBox, Yes
  213.         FileCopy, %AutoHotkeyctpl%, %contextDir%\Template\AutoHotkey.ctpl, 1
  214. }
  215. else
  216.     FileCopy, %AutoHotkeyctpl%, %contextDir%\Template\AutoHotkey.ctpl, 0
  217.  
  218. if FileExist(contextDir . "\Highlighters\AutoHotkey.chl")
  219. {
  220.     MsgBox,36,Warning,%contextDir%\Highlighters\AutoHotkey.chl already exists. Overwrite that file?
  221.     IfMsgBox, No
  222.         FileCopy, %AutoHotkeychl%, %contextDir%\Highlighters\AutoHotkey.chl, 0
  223.     IfMsgBox, Yes
  224.         FileCopy, %AutoHotkeychl%, %contextDir%\Highlighters\AutoHotkey.chl, 1
  225. }
  226. else
  227.     FileCopy, %AutoHotkeychl%, %contextDir%\Highlighters\AutoHotkey.chl, 0
  228.  
  229. exit:
  230.     gosub, deletefiles
  231.     MsgBox AutoHotkey syntax highlighting for ConTEXT has been successfully installed.
  232.     exitapp
  233. return
  234.  
  235. selectcontextdir:
  236.     FileSelectFolder, contextDir ,,0, Select the folder ConTEXT is installed in.
  237.     if errorlevel
  238.         goto exit
  239.     
  240.     if !FileExist(contextDir . "\conTEXT.exe")
  241.     {
  242.         msgbox,18,Error,This is not the folder context is installed in. Install anyway? ;`n.Abort - Exit.`nRetry - Select again.`nIgnore - Install files anyway.`n
  243.         IfMsgBox, Abort
  244.         {
  245.          gosub, deletefiles
  246.          exitapp
  247.         }
  248.  
  249.         IfMsgBox, Retry
  250.             goto selectcontextdir
  251.         IfMsgBox, Ignore
  252.         {
  253.             FileCreateDir, %contextDir%\Template
  254.             FileCreateDir, %contextDir%\Highlighters
  255.         }
  256.     }
  257. return
  258.  
  259. deletefiles:
  260.     if FileExist(autohotkeyctpl)
  261.         FileDelete, %autohotkeyctpl%
  262.     if FileExist(autohotkeychl)
  263.         FileDelete, %autohotkeychl%
  264. return
  265.  
  266. parse_hl(file,lastcharlist,firstcharlist="",bIfFirstChar=0 )
  267. {
  268.     Loop, Parse, file, `n, `n
  269.     {
  270.         firstword=
  271.         Loop, Parse, A_LoopField
  272.         {
  273.             if (firstcharlist and a_index = 1)
  274.             {
  275.                 if bIfFirstChar
  276.                 {
  277.                     if a_loopfield not in %firstcharlist%
  278.                         break
  279.                 }
  280.                 else if !bIfFirstChar
  281.                 {
  282.                     if a_loopfield in %firstcharlist%
  283.                         break
  284.                 }
  285.  
  286.             }
  287.             if A_LoopField not in %lastcharlist%
  288.                 firstword=%firstword%%A_LoopField%
  289.             else
  290.                 break
  291.         }
  292.     if firstword
  293.     out=%out%`n%firstword%
  294.     }
  295.     return out
  296. }
  297.  
  298. parse_template(ByRef Command, ByRef Desc, ByRef Out)
  299. {
  300.     Loop, parse, Out
  301.     {
  302.     
  303.         if bDesc
  304.         {
  305.             if (A_LoopField = "|")
  306.                 Desc:=Desc . " or "
  307.             else if (A_LoopField = "[" or a_loopfield = "]")
  308.                 continue
  309.             else if A_LoopField = {        ;,},`t
  310.                       Desc:=Desc . "("
  311.             else if A_LoopField = }        ;,},`t
  312.                       Desc:=Desc . ")"
  313.             else if A_LoopField = %a_tab%        ;,},`t
  314.                       Desc:=Desc . "  "
  315.             else if A_loopfield = ``
  316.             {
  317.                       prevloopfield:=a_loopfield
  318.                       continue
  319.             }
  320.             else if (A_loopfield = "n" and prevloopfield = "``")
  321.                       continue
  322.             else
  323.                 Desc:=Desc . A_LoopField
  324.             
  325.             prevloopfield:=a_loopfield
  326.  
  327.             continue
  328.         }
  329.         
  330.         if (A_LoopField = "," OR A_LoopField = " " OR A_LoopField = "(")
  331.         {
  332.         bDesc=1
  333.         Desc:=Desc . A_LoopField
  334.         }
  335.         
  336. ;         MsgBox, % Command . a_loop Field
  337.         if !bDesc
  338.             Command=%Command%%A_LoopField%
  339.     ;   MsgBox, 4, , File number %A_Index% is %A_LoopField%.`n`nContinue?
  340.     ;   IfMsgBox, No, break
  341.     }
  342.     StringReplace, Out, Out, | ,%a_space%or%a_space%, All
  343.     StringReplace, Out, Out,[,, All
  344.     StringReplace, Out, Out,],, All
  345.     StringReplace, Out, Out,{,(, All
  346.     StringReplace, Out, Out,},), All
  347.     StringReplace, Out, Out,%a_tab%,%a_space%%a_space%, All
  348.     StringReplace, Out, Out,``n,, All
  349. }
  350.